package com.example.mymatch.controller;

import com.example.mymatch.model.Dept;
import com.example.mymatch.service.IDeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;  //对某个业务服务的内容进行定义规范  编写者：吴茂景
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * 控制类的实现
 * 编写者：吴茂景
 */
@Api(tags = "部门")
@RestController
@RequestMapping("/swagger2")
public class DeptController {
    @Autowired
    private IDeptService deptService;//对某个业务服务的内容进行定义规范  编写者：吴茂景

    @CrossOrigin
    @GetMapping("dept")
    @ResponseBody
    public List<Dept> query(int id){return deptService.query(id);}

    @ApiOperation(value = "查询所有部门信息",notes = "获取部门信息返回json字符串")
    @RequestMapping("/getStr2")
    public String getDept(){
        return "My dept";
    }
    @CrossOrigin
    @ApiOperation(value = "对部门信息的添加方法")
    @GetMapping("/addDept")
    public int addDept(Dept dept){
        System.out.println("进入添加部门信息接口");
        return deptService.insertDept(dept);
    }

    @GetMapping("getAll2")
    @ApiOperation(value = "对全部部门信息的查询方法")
    public List<Dept> getAllDept(Dept dept){
        System.out.println("进入查询方法");

        List<Dept> listDept=deptService.getAllDept(dept);

        return listDept;
    }

    @PutMapping("/editDept")
    @ApiOperation(value = "对部门信息的修改方法")
    public int EditDept(@RequestBody Dept dept){
        System.out.println("进入部门修改方法");
        return deptService.updateDept(dept);
    }

    @GetMapping("/delDept")
    @ApiOperation(value = "对部门信息的删除方法")
    public int Delete(String name){
        System.out.println("进入部门删除方法");
        int returnValue=0;
        if (name!=null){
            Dept dept=new Dept();
            dept.setDeptName(name);
            returnValue= deptService.deleteDept(dept);
        }
        return returnValue;
    }

    @GetMapping("/getOne2")
    @ApiOperation(value = "对单条部门信息的查询方法")
    public  Dept getDept(String name){
        Dept dept=new Dept();
        System.out.println("进入部门查询方法");
        if (name!=null){
            Dept dept1=new Dept();
            dept1.setDeptName(name);
            dept=deptService.getDept(dept1);
            System.out.println("返回的数据集合为："+dept.getDeptName());
        }
        return dept;
    }
}
